package cc.rengu.igas.channel.alipay.core.service.trans;

import cc.rengu.igas.channel.alipay.common.constant.*;
import cc.rengu.igas.channel.alipay.common.enums.RespCodeEnum;
import cc.rengu.igas.channel.alipay.core.model.ChnlBizResponse;
import cc.rengu.igas.channel.alipay.core.service.base.MchntService;
import cc.rengu.igas.channel.alipay.facade.request.AliCreateMerchantRequest;
import cc.rengu.igas.channel.alipay.facade.response.AliCreateMerchantResponse;
import cc.rengu.jradp.schedule.Schedule;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.dao.CertInfoMapper;
import cc.rengu.oltp.service.common.dao.SecPlanInfoMapper;
import cc.rengu.oltp.service.common.dao.impl.CertInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.SecPlanInfoMapperImpl;
import cc.rengu.oltp.service.common.entity.*;
import cc.rengu.oltp.service.common.enums.ChannelEnum;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.realize.SysParamService;
import cc.rengu.oltp.service.realize.impl.SysParamServiceImpl;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.StringUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.FileItem;
import com.alipay.api.request.AlipayOpenAgentCancelRequest;
import com.alipay.api.request.AlipayOpenAgentConfirmRequest;
import com.alipay.api.request.AlipayOpenAgentCreateRequest;
import com.alipay.api.request.AlipayOpenAgentFacetofaceSignRequest;
import com.alipay.api.response.AlipayOpenAgentCancelResponse;
import com.alipay.api.response.AlipayOpenAgentConfirmResponse;
import com.alipay.api.response.AlipayOpenAgentCreateResponse;
import com.alipay.api.response.AlipayOpenAgentFacetofaceSignResponse;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * 商户入驻
 */
public class CreateMerchantService extends MchntService {

    @Override
    protected Object beforeBizProcess() throws Exception {
        AliCreateMerchantRequest aliCreateMerchantRequest = new AliCreateMerchantRequest();
        ConvertUtil.convertOutput(aliCreateMerchantRequest);
        return aliCreateMerchantRequest;
    }

    @Override
    protected ChnlBizResponse callBizService(Object request) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        int iReturnCode = 0;
        AliCreateMerchantResponse aliCreateMerchantResponse = new AliCreateMerchantResponse();
        AliCreateMerchantRequest aliCreateMerchantRequest = (AliCreateMerchantRequest) request;
        DstChannelCfg dstChannelCfg = (DstChannelCfg) xmlTreeUtil.getXmlTreeObjectValue(AlipayTreeNodeConstant.DST_CHANNEL_CFG, DstChannelCfg.class);
        DstChannelInfo dstChannelInfo = (DstChannelInfo) xmlTreeUtil.getXmlTreeObjectValue(AlipayTreeNodeConstant.DST_CHANNEL_INFO, DstChannelInfo.class);

        ConvertUtil.convertInput(aliCreateMerchantRequest);
        xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.TXN_NUM, aliCreateMerchantRequest.getHeader().getTxnNum());
        /* 根据通道标识调用不同通道进行支付 */
        Schedule schedule = new Schedule();
        if (ChannelEnum.ALIP.getChannelType().equals(aliCreateMerchantRequest.getChannelId())) {
            return directCreateMchnt(aliCreateMerchantRequest, dstChannelInfo, dstChannelCfg);
        } else if (ChannelEnum.NUAL.getChannelType().equals(aliCreateMerchantRequest.getChannelId()) ||
                ChannelEnum.UPAL.getChannelType().equals(aliCreateMerchantRequest.getChannelId())) {
            xmlTreeUtil.setXmlTreeStringValue(AlipayTreeNodeConstant.ALI_METHOD, "ant.merchant.expand.indirect.create");
            xmlTreeUtil.setXmlTreeStringValue(AlipayTreeNodeConstant.ALIPAY_APPID, dstChannelCfg.getAppId());
            xmlTreeUtil.setXmlTreeStringValue(AlipayTreeNodeConstant.ALIPAY_PID, dstChannelCfg.getProviderMchntNo());
            xmlTreeUtil.setXmlTreeStringValue(AlipayTreeNodeConstant.ALIPAY_ORGPID, dstChannelCfg.getProviderMchntNo());
            iReturnCode = schedule.callService(dstChannelInfo.getDstServiceName(), 0);
        } else {
            rglog.error("不支持的通道选择，channelId:<{}>", aliCreateMerchantRequest.getChannelId());
            throw new BizException(RespCodeEnum.CHANNEL_CONFIG_NOT_EXIST.getRespCode(), RespCodeEnum.CHANNEL_CONFIG_NOT_EXIST.getRespDesc());
        }
        if (xmlTreeUtil.isExist(AlipayTreeNodeConstant.DEFINE_HTTP_URL_NODE)) {
            xmlTreeUtil.deleteXmlTreeNode(AlipayTreeNodeConstant.DEFINE_HTTP_URL_NODE);
        }
        if (0 != iReturnCode && 98 != iReturnCode) {
            rglog.error("调用支付宝服务失败，iReturnCode:<{}>", iReturnCode);
            throw new BizException(RespCodeEnum.CALL_BIZ_SERVICE_ERROR.getRespCode(), RespCodeEnum.CALL_BIZ_SERVICE_ERROR.getRespDesc());
        } else if (98 == iReturnCode) {
            rglog.error("调用支付宝服务超时，iReturnCode:<{}>", iReturnCode);
            throw new BizException(RespCodeEnum.TIME_OUT_ERROR.getRespCode(), RespCodeEnum.TIME_OUT_ERROR.getRespDesc());
        }
        ConvertUtil.convertOutput(aliCreateMerchantResponse);
        String code = xmlTreeUtil.getXmlTreeStringValue(AlipayTreeNodeConstant.ALI_RET_CODE);
        String msg = xmlTreeUtil.getXmlTreeStringValue(AlipayTreeNodeConstant.ALI_RET_MSG);
        String subCode = xmlTreeUtil.getXmlTreeStringValue(AlipayTreeNodeConstant.ALI_RET_SUBCODE);
        String subMsg = xmlTreeUtil.getXmlTreeStringValue(AlipayTreeNodeConstant.ALI_RET_SUBMSG);
        if (!AlipayParamConstant.AILPAY_SUCCESS_CODE.equals(code)) {
            rglog.error("调用第三方服务失败,respCode=[{}],respDesc=[{}]", code, msg);
            aliCreateMerchantResponse.setRespCode((null == subCode) ? code : subCode);
            aliCreateMerchantResponse.setRespDesc((null == subMsg) ? msg : subMsg);
        } else {
            aliCreateMerchantResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
            aliCreateMerchantResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        }
        ChnlBizResponse chnlBizResponse = new ChnlBizResponse();
        chnlBizResponse.setResult(aliCreateMerchantResponse);
        return chnlBizResponse;
    }

    @Override
    protected void afterBizProcess(ChnlBizResponse response) throws Exception {
        AliCreateMerchantResponse aliCreateMerchantResponse = (AliCreateMerchantResponse) response.getResult();
        ConvertUtil.convertInput(aliCreateMerchantResponse);
    }

    ChnlBizResponse directCreateMchnt(AliCreateMerchantRequest aliCreateMerchantRequest, DstChannelInfo dstChannelInfo, DstChannelCfg dstChannelCfg) throws Exception {
        AliCreateMerchantResponse aliCreateMerchantResponse = new AliCreateMerchantResponse();
        ChnlBizResponse chnlBizResponse = new ChnlBizResponse();
        String instId = aliCreateMerchantRequest.getHeader().getInstId();

        /* 获取支付宝通讯配置参数 */
        SysParamService sysParamService = new SysParamServiceImpl();
        /*获取请求url*/
        SysParam sysParam = sysParamService.getSysParamInfo(instId, AlipayConfigConstant.ALIPAY_CONF_NODE, AlipayConfigConstant.ALIPAY_PAY_NET_URL);
        if (null == sysParam || StringUtil.isEmptyOrNull(sysParam.getParamValue())) {
            rglog.error("未配置支付宝直连专线URL地址，请配置");
            throw new BizException(RespCodeEnum.CONFIG_PARAM_NOT_EXIST.getRespCode(), RespCodeEnum.CONFIG_PARAM_NOT_EXIST.getRespDesc());
        }
        String requestUrl = sysParam.getParamValue();
        /*互联网代理IP*/
        sysParam = sysParamService.getSysParamInfo(instId, AlipayConfigConstant.ALIPAY_CONF_NODE, AlipayConfigConstant.ALIPAY_PROXY_NET_IP);
        String proxyIp = (null == sysParam || StringUtil.isEmptyOrNull(sysParam.getParamValue())) ? null : sysParam.getParamValue().trim();
        /*互联网代理端口*/
        sysParam = sysParamService.getSysParamInfo(instId, AlipayConfigConstant.ALIPAY_CONF_NODE, AlipayConfigConstant.ALIPAY_PROXY_NET_PORT);
        String proxyPort = (null == sysParam || StringUtil.isEmptyOrNull(sysParam.getParamValue())) ? null : sysParam.getParamValue().trim();
        /*报文类型*/
        sysParam = sysParamService.getSysParamInfo(instId, AlipayConfigConstant.ALIPAY_CONF_NODE, AlipayConfigConstant.ALIPAY_MSG_TYPE);
        String msgType = (null == sysParam || StringUtil.isEmptyOrNull(sysParam.getParamValue())) ? "json" : sysParam.getParamValue().trim();
        /*字符集*/
        sysParam = sysParamService.getSysParamInfo(instId, AlipayConfigConstant.ALIPAY_CONF_NODE, AlipayConfigConstant.ALIPAY_CHARSET);
        String charset = (null == sysParam || StringUtil.isEmptyOrNull(sysParam.getParamValue())) ? "UTF-8" : sysParam.getParamValue().trim();
        /*签名验签方式*/
        sysParam = sysParamService.getSysParamInfo(instId, AlipayConfigConstant.ALIPAY_CONF_NODE, AlipayConfigConstant.ALIPAY_SIGN_TYPE);
        String signType = (null == sysParam || StringUtil.isEmptyOrNull(sysParam.getParamValue())) ? "RSA2" : sysParam.getParamValue().trim();

        /* 根据通道安全计划获取安全计划 */
        String priKey = null;
        String pubKey = null;
        SecPlanInfoMapper secPlanInfoMapper = new SecPlanInfoMapperImpl();
        CertInfoMapper certInfoMapper = new CertInfoMapperImpl();
        List<SecPlanInfo> secPlanInfoList = secPlanInfoMapper.selectSecPlanInfoBySecPlanId(instId, dstChannelCfg.getSecPlanId());

        /* 获取签名验签证书（私钥） */
        Optional<SecPlanInfo> secPlanInfoOptSign = secPlanInfoList.stream().filter(item -> item.getSecPlanType().equals(AlipayParamConstant.SIGN_CERT_TYPE)).findFirst();
        if (secPlanInfoOptSign.isPresent()) {
            CertInfo certInfoPri = certInfoMapper.selectCertInfoByPrimaryKey(instId + secPlanInfoOptSign.get().getSecPlanId() + secPlanInfoOptSign.get().getSecPlanType());
            if (certInfoPri != null) {
                priKey = certInfoPri.getCertValue();
            }
        }

        /* 获取签名验签证书（公钥） */
        Optional<SecPlanInfo> secPlanInfoOpt = secPlanInfoList.stream().filter(item -> item.getSecPlanType().equals(AlipayParamConstant.VERIFY_CERT_TYPE)).findFirst();
        if (secPlanInfoOpt.isPresent()) {
            CertInfo certInfoPub = certInfoMapper.selectCertInfoByPrimaryKey(instId + secPlanInfoOpt.get().getSecPlanId() + secPlanInfoOpt.get().getSecPlanType());
            if (certInfoPub != null) {
                pubKey = certInfoPub.getCertValue();
            }
        }

        /* 调用支付宝开启代商户签约、创建应用事务 */
        rglog.debug("aliPayUrl = <{}>;appId = <{}>;priKey = <{}>;msgType = <{}>,charset = <{}>,pubKey = <{}>,signType = <{}>,proxyIp = <{}>,proxyPort = <{}>",
                requestUrl, dstChannelCfg.getAppId(), priKey, msgType, charset, pubKey, signType, proxyIp, proxyPort);
        AlipayClient alipayClient;
        if (StringUtil.isEmptyOrNull(proxyIp) || StringUtil.isEmptyOrNull(proxyPort)) {
            alipayClient = new DefaultAlipayClient(requestUrl, dstChannelCfg.getAppId(), priKey, msgType, charset, pubKey, signType);
        } else {
            alipayClient = new DefaultAlipayClient(requestUrl, dstChannelCfg.getAppId(), priKey, msgType, charset, pubKey, signType, proxyIp, proxyPort);
        }

        /* 开启代商户签约、创建应用事务 */
        AlipayOpenAgentCreateRequest alipayOpenAgentCreateRequest = new AlipayOpenAgentCreateRequest();
        Map<String, String> contactInfoMap = new HashMap<>();
        contactInfoMap.put("contact_name", aliCreateMerchantRequest.getContactInfoList().get(0).getContact());
        contactInfoMap.put("contact_mobile", aliCreateMerchantRequest.getContactInfoList().get(0).getContactPhone());
        contactInfoMap.put("contact_email", aliCreateMerchantRequest.getContactInfoList().get(0).getContactEmail());
        Map<String, String> bizContentMap = new HashMap<>();
        if (StringUtil.isEmptyOrNull(aliCreateMerchantRequest.getSource())) {
            bizContentMap.put("account", dstChannelCfg.getProviderMchntNo());
        } else {
            bizContentMap.put("account", aliCreateMerchantRequest.getSource());
        }
        bizContentMap.put("contact_info", JSON.toJSONString(contactInfoMap));
        alipayOpenAgentCreateRequest.setBizContent(JSON.toJSONString(bizContentMap));
        rglog.debug("创建事务请求参数：{}", JSON.toJSONString(aliCreateMerchantRequest));
        AlipayOpenAgentCreateResponse alipayOpenAgentCreateResponse = alipayClient.execute(alipayOpenAgentCreateRequest);
        if (alipayOpenAgentCreateResponse.isSuccess()) {
            aliCreateMerchantResponse.setBatchNo(alipayOpenAgentCreateResponse.getBatchNo());
            rglog.debug("当前事务编号:{},操作事务状态:{}", alipayOpenAgentCreateResponse.getBatchNo(), alipayOpenAgentCreateResponse.getBatchStatus());
            /* 代签约当面付产品 */
            alipayOpenAgentFaceToFaceSign(alipayClient, alipayOpenAgentCreateResponse.getBatchNo(), aliCreateMerchantRequest, aliCreateMerchantResponse);
            /* 提交代商户签约、创建应用事务 */
            if (RespCodeEnum.TRANS_SUCCESS.getRespCode().equals(aliCreateMerchantResponse.getRespCode())) {
                AlipayOpenAgentConfirmRequest alipayOpenAgentConfirmRequest = new AlipayOpenAgentConfirmRequest();
                Map<String, String> confirmParamMap = new HashMap<>();
                confirmParamMap.put("batch_no", alipayOpenAgentCreateResponse.getBatchNo());
                alipayOpenAgentConfirmRequest.setBizContent(JSON.toJSONString(confirmParamMap));
                rglog.debug("提交事务请求参数：{}", JSON.toJSONString(alipayOpenAgentConfirmRequest));
                AlipayOpenAgentConfirmResponse alipayOpenAgentConfirmResponse = alipayClient.execute(alipayOpenAgentConfirmRequest);
                if (alipayOpenAgentConfirmResponse.isSuccess()) {
                    rglog.debug("提交事务成功:{}", JSON.toJSONString(alipayOpenAgentConfirmResponse));
                } else {
                    rglog.debug("提交事务失败:{}", JSON.toJSONString(alipayOpenAgentConfirmResponse));
                    aliCreateMerchantResponse.setRespCode((null == alipayOpenAgentConfirmResponse.getSubCode()) ? alipayOpenAgentConfirmResponse.getCode() : alipayOpenAgentConfirmResponse.getSubCode());
                    aliCreateMerchantResponse.setRespDesc((null == alipayOpenAgentConfirmResponse.getSubMsg()) ? alipayOpenAgentConfirmResponse.getMsg() : alipayOpenAgentConfirmResponse.getSubMsg());
                }
            }
        } else {
            aliCreateMerchantResponse.setRespCode((null == alipayOpenAgentCreateResponse.getSubCode()) ? alipayOpenAgentCreateResponse.getCode() : alipayOpenAgentCreateResponse.getSubCode());
            aliCreateMerchantResponse.setRespDesc((null == alipayOpenAgentCreateResponse.getSubMsg()) ? alipayOpenAgentCreateResponse.getMsg() : alipayOpenAgentCreateResponse.getSubMsg());
        }
        chnlBizResponse.setResult(aliCreateMerchantResponse);
        return chnlBizResponse;
    }

    /**
     * 直联支付宝ISV代商户签约
     *
     * @param alipayClient              调用服务句柄
     * @param batchNo                   全局唯一事务编号
     * @param aliCreateMerchantRequest  商户入驻请求信息
     * @param aliCreateMerchantResponse 商户入驻应答信息
     * @throws AlipayApiException 异常
     */
    private void alipayOpenAgentFaceToFaceSign(AlipayClient alipayClient, String batchNo, AliCreateMerchantRequest aliCreateMerchantRequest, AliCreateMerchantResponse aliCreateMerchantResponse) throws AlipayApiException {
        AlipayOpenAgentFacetofaceSignRequest alipayOpenAgentFacetofaceSignRequest = new AlipayOpenAgentFacetofaceSignRequest();
        alipayOpenAgentFacetofaceSignRequest.setBatchNo(batchNo);
        /* 商家经营类目编码，如：A0001_B0199 */
        alipayOpenAgentFacetofaceSignRequest.setMccCode(aliCreateMerchantRequest.getAlipayCategory());
        /* 服务费率 */
        alipayOpenAgentFacetofaceSignRequest.setRate("");
        /* 签约且授权标识 */
        alipayOpenAgentFacetofaceSignRequest.setSignAndAuth(false);
        if (null != aliCreateMerchantRequest.getSignInfo()) {
            /* 企业特殊资质图片 */
//            alipayOpenAgentFacetofaceSignRequest.setSpecialLicensePic("");
            /* 营业执照号码 */
            if (!StringUtil.isEmptyOrNull(aliCreateMerchantRequest.getSignInfo().getBusinessLicenseNo())) {
                alipayOpenAgentFacetofaceSignRequest.setBusinessLicenseNo(aliCreateMerchantRequest.getSignInfo().getBusinessLicenseNo());
            }
            /* 营业执照图片 */
            if (!StringUtil.isEmptyOrNull(aliCreateMerchantRequest.getSignInfo().getBusinessLicensePic())) {
                FileItem specialLicensePic = new FileItem(aliCreateMerchantRequest.getSignInfo().getBusinessLicensePic());
                alipayOpenAgentFacetofaceSignRequest.setBusinessLicensePic(specialLicensePic);
            }
            /* 营业执照授权函图片 */
//            alipayOpenAgentFacetofaceSignRequest.setBusinessLicenseAuthPic("");
            /* 店铺内景图片 */
            if (!StringUtil.isEmptyOrNull(aliCreateMerchantRequest.getSignInfo().getShopScenePic())) {
                FileItem shopScenePic = new FileItem(aliCreateMerchantRequest.getSignInfo().getShopScenePic());
                alipayOpenAgentFacetofaceSignRequest.setShopScenePic(shopScenePic);
            }
            /* 店铺门头照图片 */
            if (!StringUtil.isEmptyOrNull(aliCreateMerchantRequest.getSignInfo().getShopSignBoardPic())) {
                FileItem shopSignBoardPic = new FileItem(aliCreateMerchantRequest.getSignInfo().getShopSignBoardPic());
                alipayOpenAgentFacetofaceSignRequest.setShopSignBoardPic(shopSignBoardPic);
            }
        }
        /* 营业期限是否长期有效 */
        alipayOpenAgentFacetofaceSignRequest.setLongTerm(false);
        /* 营业期限 */
        alipayOpenAgentFacetofaceSignRequest.setDateLimitation("");
        /* 店铺名称 */
//        alipayOpenAgentFacetofaceSignRequest.setShopName(aliCreateMerchantRequest.getMchntName());
        /* 店铺地址 */
//        SignAddressInfo signAddressInfo = new SignAddressInfo();
//        signAddressInfo.setCountryCode("156");
//        signAddressInfo.setProvinceCode(aliCreateMerchantRequest.getAddressInfoList().get(0).getProvinceCode());
//        signAddressInfo.setCityCode(aliCreateMerchantRequest.getAddressInfoList().get(0).getCityCode());
//        signAddressInfo.setDistrictCode(aliCreateMerchantRequest.getAddressInfoList().get(0).getDistrictCode());
//        signAddressInfo.setDetailAddress(aliCreateMerchantRequest.getAddressInfoList().get(0).getAddress());
//        signAddressInfo.setLongitude(aliCreateMerchantRequest.getAddressInfoList().get(0).getLongitude());
//        signAddressInfo.setLatitude(aliCreateMerchantRequest.getAddressInfoList().get(0).getLatitude());
//        alipayOpenAgentFacetofaceSignRequest.setShopAddress(signAddressInfo);
        /* 被邀请授权的营业执照法人手机号码 */
//        alipayOpenAgentFacetofaceSignRequest.setBusinessLicenseMobile(aliCreateMerchantRequest.getContactInfoList().get(0).getContactPhone());
        rglog.debug("代签约请求参数：{}", JSON.toJSONString(alipayOpenAgentFacetofaceSignRequest));
        AlipayOpenAgentFacetofaceSignResponse alipayOpenAgentFacetofaceSignResponse = alipayClient.execute(alipayOpenAgentFacetofaceSignRequest);
        if (alipayOpenAgentFacetofaceSignResponse.isSuccess()) {
            rglog.info("代签约当面付产品成功:{}", JSON.toJSONString(alipayOpenAgentFacetofaceSignResponse));
            aliCreateMerchantResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
            aliCreateMerchantResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        } else {
            rglog.info("代签约当面付产品失败:{}", JSON.toJSONString(alipayOpenAgentFacetofaceSignResponse));
            AlipayOpenAgentCancelRequest alipayOpenAgentCancelRequest = new AlipayOpenAgentCancelRequest();
            Map<String, String> concelParamMap = new HashMap<>();
            concelParamMap.put("batch_no", batchNo);
            alipayOpenAgentCancelRequest.setBizContent(JSON.toJSONString(concelParamMap));
            AlipayOpenAgentCancelResponse alipayOpenAgentCancelResponse = alipayClient.execute(alipayOpenAgentCancelRequest);
            if (alipayOpenAgentCancelResponse.isSuccess()) {
                rglog.info("取消签约当面付产品成功:{}", JSON.toJSONString(alipayOpenAgentCancelResponse));
                aliCreateMerchantResponse.setRespCode((null == alipayOpenAgentFacetofaceSignResponse.getSubCode()) ? alipayOpenAgentFacetofaceSignResponse.getCode() : alipayOpenAgentFacetofaceSignResponse.getSubCode());
                aliCreateMerchantResponse.setRespDesc((null == alipayOpenAgentFacetofaceSignResponse.getSubMsg()) ? alipayOpenAgentFacetofaceSignResponse.getMsg() : alipayOpenAgentFacetofaceSignResponse.getSubMsg());
            } else {
                rglog.info("取消签约当面付产品失败:{}", JSON.toJSONString(alipayOpenAgentCancelResponse));
                aliCreateMerchantResponse.setRespCode((null == alipayOpenAgentCancelResponse.getSubCode()) ? alipayOpenAgentCancelResponse.getCode() : alipayOpenAgentCancelResponse.getSubCode());
                aliCreateMerchantResponse.setRespDesc((null == alipayOpenAgentCancelResponse.getSubMsg()) ? alipayOpenAgentCancelResponse.getMsg() : alipayOpenAgentCancelResponse.getSubMsg());
            }
        }
    }
}
